// 单条评论组件

import "./index.less";
import {Image, Text, View} from "@tarojs/components";
import {GLOBAL_IMAGE} from "../../constant/contant";
import Taro from "@tarojs/taro";
import {API_PATH} from "../../api/api";

export function CommentItem(props) {
    const {isSelf, commentObj, commentRemove, myName, selfAvatar} = props;

    // const commentObj = {
    //     updateTime: "2023-09-26 19:00:11",
    //     content: "这是一条评论这是一条评论这是一条评论这是一条评论这是一条评论这是一条评论这是一条评论这是一条评论",
    //     nickName: "用户昵称",
    //     avatar: GLOBAL_IMAGE.ach_test,
    //     status: 0,
    //     isDelete: 0,
    // }

    const removeClick = () => {
        Taro.showModal({
            title: '',
            content: `确定删除该合作需求吗？`,
            success: function (res) {
                if (res.confirm) {
                    commentRemove(commentObj.id)
                }
            }
        })
    }

    const getAvatar = () => {
        if (selfAvatar) {
            return API_PATH + selfAvatar;
        } else {
            return commentObj?.avatar ? API_PATH + commentObj.avatar : GLOBAL_IMAGE.default_avatar;
        }
    }

    return (
        <View className={"commentItem"}>
            <View className={"commentItem_top"}>
                <View className={"commentItem_avatar"}>
                    <Image src={getAvatar()}/>
                </View>
                <View className={"commentItem_info"}>
                    <View className={"commentItem_user"}>
                        <Text>{myName || commentObj?.nickName}</Text>
                    </View>
                    <View className={"commentItem_time"}>
                        <Text>{commentObj?.updateTime}</Text>
                    </View>
                </View>
            </View>
            <View className={"commentItem_bot"}>
                <Text userSelect={true}>{commentObj?.content}</Text>
            </View>
            {
                isSelf && <View className={"self_tool"}>
                    <View className={"self_remove"} onClick={removeClick}>
                        <Text>删除</Text>
                    </View>
                    {
                        commentObj?.status === "0" && <View className={"self_line"}/>
                    }
                    {
                        commentObj?.status === "0" &&
                        <View className={"self_see"}>
                            <Image src={GLOBAL_IMAGE.see}/>
                        </View>
                    }
                </View>
            }
        </View>
    )
}
